#include "DDevice.h"

DDevice::DDevice(void)
{
	m_pDevice	= 0;
	m_pD3d		= 0;
}

DDevice::~DDevice(void)
{
}

bool DDevice::CreateDevice( HWND hWnd )
{
	m_hWnd = hWnd;
	m_pD3d = ::Direct3DCreate9(D3D_SDK_VERSION);
	if( m_pD3d == NULL)
		return false;
	
	ZeroMemory(&m_Param,sizeof(D3DPRESENT_PARAMETERS));

	m_Param.Windowed				= TRUE;
	m_Param.SwapEffect				= D3DSWAPEFFECT_DISCARD;
	m_Param.BackBufferFormat		= D3DFMT_UNKNOWN;
	m_Param.PresentationInterval	= D3DPRESENT_INTERVAL_IMMEDIATE;
	m_Param.EnableAutoDepthStencil	= TRUE;
	m_Param.AutoDepthStencilFormat	= D3DFMT_D16;

	if( FAILED(m_pD3d->CreateDevice(0, D3DDEVTYPE_HAL, m_hWnd, 
							D3DCREATE_HARDWARE_VERTEXPROCESSING,
							&m_Param, &m_pDevice) ) ) 
	{
		MessageBox(NULL,_T("CreateDevice Failed"),_T("DDevice Error"),MB_OK);
		return false;
	}

	m_pDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
	return true;
}

void DDevice::ReleaseDevice()
{
	if(m_pDevice)
		m_pDevice->Release();

	if(m_pD3d)
		m_pD3d->Release();
}
